<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"  
      xmlns:f="http://java.sun.com/jsf/core"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content">
            <!--FILTER FORM START -->
            <div class="Post">       
                <h:form>
                    <p:panel  id="pnl" header="Filter" toggleable="true" collapsed="true"  toggleSpeed="100" closeSpeed="100" widgetVar="panel">  

                        <h:panelGrid id="filter" columns="6" cellpadding="9" title="Filter">  
                            <h:outputText value="Type of task" />
                            <p:selectCheckboxMenu value="#{studentAsSubmitBean.selectedTypes}" label="Type" >  
                                <f:selectItems value="#{studentAsSubmitBean.typeOfAssignment}" />  
                            </p:selectCheckboxMenu> 
                            <h:outputText value="State of task" />
                            <p:selectCheckboxMenu value="#{studentAsSubmitBean.selectedStates}" label="State" >  
                                <f:selectItems value="#{studentAsSubmitBean.states}" />  
                            </p:selectCheckboxMenu> 
                            <h:outputText value="Subject of assignment" />
                            <p:selectCheckboxMenu value="#{studentAsSubmitBean.selectedSubject}" label="Subject" >  
                                <f:selectItems value="#{studentAsSubmitBean.subjects}" var="subjectNow" itemValue="#{subjectNow.code}"
                                               itemLabel="#{subjectNow.code}"/>  
                            </p:selectCheckboxMenu> 
                        </h:panelGrid>
                        <p:commandButton value="Apply filter"  action="#{studentAsSubmitBean.applyFilter()}" ajax="true" update=":task:assignmentTable"/>   
                    </p:panel>  
                </h:form>            
            </div>
            <!--FILTER FORM END -->
            <!--Main task datatable FORM Start -->
            <div class="Post">             
                <h:form id="task">
                    <p:dataTable 
                        var="task" value="#{studentAsSubmitBean.submitAssingment}" paginator="true" rows="10"  
                        selection="#{studentAsSubmitBean.selectedAssignmentSubmit}" selectionMode="single"  
                        rowKey="#{task.id}" paginatorAlwaysVisible="false"
                        widgetVar="taskTable" id="assignmentTable" liveScroll="true" 
                        >  
                        <p:ajax event="rowSelect"  
                                update=":submit:display"  oncomplete="taskDialog.show()" />    
                        <f:facet name="header">                    
                            <h:outputText value="Submitted task"/>                                     
                        </f:facet>  
                        <p:column headerText="Label">  
                            <h:outputText value="#{task.assignment.template.name}" />  
                        </p:column>   
                        <p:column headerText="Last submit">   
                            <h:outputText value="#{task.dateOfSubmit}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{task.assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Evaluation">  
                            <h:outputText value="#{task.dateOfEvaluation}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="State">    
                            <h:outputText value="#{task.stateOfTask}"/>
                        </p:column>
                        <p:column headerText="Type">                      
                            <h:outputText value="#{task.assignment.type}" /> 
                        </p:column>
                        <p:column headerText="Kantor">            
                            <h:outputText value="#{task.assignment.template.kantor.name} #{task.assignment.template.kantor.surname}" /> 
                        </p:column>
                        <p:column headerText="Subject">   
                            <h:outputText value="#{task.assignment.subject.code}" /> 
                        </p:column>
                        <p:column headerText="Grade">   
                            <h:outputText value="#{task.grade}" /> 
                        </p:column>
                    </p:dataTable>   
                    <h:outputText value="To select or unselect use CTRL" />
                </h:form>  
            </div>
            <!--Main task datatable FORM END -->

            <!--Selected task details dialog START-->
            <p:dialog header="Task Detail" widgetVar="taskDialog" resizable="true"  modal="true"
                      width="900" height="600" dynamic="true"  appendToBody="true"> 
                <h:form id="submit">
                    <h:panelGrid id="display" columns="2" cellpadding="6"  title="Assigned Task">  
                        <h:outputText value="Label"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.name}" />
                        <h:outputText value="Description"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.description}" escape="false">
                            <f:converter converterId="StringFormatter" />
                        </h:outputText>
                        <h:outputText value="Subject"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.subject.code}" />
                        <h:outputText value="Date of assign"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.dateOfAssignment}" >
                           <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Deadline"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.deadline}" >
                           <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Date of submit"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.dateOfSubmit}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Date of evaluation"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.dateOfEvaluation}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Grade"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.grade}" >¨
                        </h:outputText>
                        <h:outputText value="Evaluation"/>
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.evaluation}" />
                        <h:outputText value="Kantor:"/>                           
                        <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.kantor.name} 
                                      #{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.kantor.surname}" />
                        <h:outputText value="Kantor e-mail:" />
                        <h:outputLink value="mailto:#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.kantor.email}">
                            <f:param name="subject" value="TaskPro" />
                            <h:outputText value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.kantor.email}" />
                        </h:outputLink>
                        <h:outputText value="Submited file" />
                        <p:commandButton value="Submited files" action="#{studentAsSubmitBean.loadVersions()}" ajax="true"  onclick="dlg1.show();" update=":dialogFiles"/> 
                        <h:outputText value="Template file" />
                        <p:commandButton value="Template files" ajax="true"  onclick="fileDialog.show();" update=":templateFiles"/> 
                    </h:panelGrid>  

                    <p:commandButton value="Close"  action="taskDialog.close()" 
                                     ajax="false"></p:commandButton>
                </h:form>
            </p:dialog>      
            <!--Selected task details dialog END-->

            <!--Selected task submitted files START -->
            <p:dialog width="870" height="400" header="Submitted files with task: #{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.name}"
                      widgetVar="dlg1" modal="true" dynamic="true" appendToBody="true"
                      >
                <h:form id="dialogFiles">
                    <p:dataTable var="taskFile" value="#{studentAsSubmitBean.versions}" 
                                 rowKey="#{taskFile.id}" paginator="true" 
                                 paginatorAlwaysVisible="false" rows="10" >  
                        <p:column headerText="File" >  
                            <div class="refBody">
                            <p:commandLink value="#{taskFile.fileName}" ajax="false">  
                                <p:fileDownload value="#{studentAsSubmitBean.downloadFilesByTask(taskFile)}" />  
                            </p:commandLink> 
                                </div>
                        </p:column>
                        <p:column headerText="size" >  
                            <h:outputText title="size" value="#{taskFile.fileSize}"  >
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Description">  
                            <h:outputText value="#{taskFile.description}" >  
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Evaluation">  
                            <h:outputText value="#{taskFile.evaluation}" />  
                        </p:column>
                        <p:column headerText="Date of submit">  
                            <h:outputText value="#{taskFile.version.dateOfSubmit}" >
                                 <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Number of version">  
                            <h:outputText value="#{taskFile.version.numberOfVersion}" />  
                        </p:column>
                        <p:column headerText="Sender">  
                            <h:outputText value="#{taskFile.version.submittedStudent.name} #{taskFile.version.submittedStudent.surname}" />  
                        </p:column>
                    </p:dataTable>
                    <p:commandButton value="Close" onclick="dlg1.hide()"  
                                     ajax="true"></p:commandButton>
                </h:form>                 
            </p:dialog>
            <!--Selected task submitted files END -->

            <!--Selected task template files START -->
            <p:dialog width="870" height="400" header="Submitted files with task: #{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.name}"
                      widgetVar="fileDialog" modal="true" dynamic="true" appendToBody="true"
                      >
                <h:form id="templateFiles">
                    <p:dataTable var="templateFile" value="#{studentAsSubmitBean.selectedAssignmentSubmit.assignment.template.templateFiles}" 
                                 rowKey="#{templateFile.id}" paginator="true" 
                                 paginatorAlwaysVisible="false" rows="10" >  
                        <p:column headerText="File" >  
                            <div class="refBody">
                            <p:commandLink value="#{templateFile.fileName}" ajax="false">  
                                <p:fileDownload value="#{studentAsSubmitBean.download(templateFile)}" />  
                            </p:commandLink> 
                            </div>
                        </p:column>
                        <p:column headerText="Size" >  
                            <h:outputText title="file" value="#{templateFile.fileSize}"  />  
                        </p:column>
                    </p:dataTable>
                    <p:commandButton value="Close" onclick="fileDialog.hide()"   
                                     ajax="true"></p:commandButton>
                </h:form>
            </p:dialog>   
            <!--Selected task template files END -->
        </ui:define>
    </ui:composition>
</html>